package com.azt.front.action.wechat;

import com.alibaba.fastjson.JSONObject;
import com.azt.api.pojo.Dictionary;
import com.azt.api.pojo.Meeting;
import com.azt.api.pojo.SignUp;
import com.azt.api.pojo.User;
import com.azt.api.pojo.req.SignUpMemberReq;
import com.azt.api.pojo.req.SignUpReq;
import com.azt.api.service.DictionaryService;
import com.azt.api.service.MeetingService;
import com.azt.api.service.SignUpService;
import com.azt.api.service.SignupMemberService;
import com.azt.front.utils.ContextUtil;
import com.azt.service.wechat.WeChatConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * 微信，会议报名相关
 * Created by LiQZ on 2017/3/28.
 */
@Controller
@RequestMapping("conference")
public class ConferenceAction {

    private static final Logger logger = LoggerFactory.getLogger(ConferenceAction.class);

    @Autowired
    private SignupMemberService signupMemberService;

    @Autowired
    private SignUpService signUpService;

    @Autowired
    private MeetingService meetingService;

    @RequestMapping(value = "signup", method = RequestMethod.GET)
    public String signUp(Model model) {
        Meeting meeting = meetingService.getDefaultMeeting();
        model.addAttribute("meeting", meeting);
        return "wechat/conference/signup";
    }

    @ResponseBody
    @RequestMapping(value = "signup", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public JSONObject signUp(SignUpReq req) {
        signUpService.save(req);
        // 兼容老页面的 App.api(xxx, data).then 这种
        JSONObject obj = new JSONObject();
        obj.put("result", "保存成功");
        return obj;
    }

    @RequestMapping(value = "join", method = RequestMethod.GET)
    public String join() {
        return "wechat/conference/join";
    }

    @ResponseBody
    @RequestMapping(value = "join", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public JSONObject join(SignUpMemberReq req) {
        // 获取当前用户(可能没有)
        User user = ContextUtil.getUser();
        if (user != null) {
            req.setUserId(user.getId());
        }
        signupMemberService.save(req);
        // 兼容老页面的 App.api(xxx, data).then 这种
        JSONObject obj = new JSONObject();
        obj.put("result", "保存成功");
        return obj;
    }

    @RequestMapping("joindone")
    public String joindone() {
        return "wechat/conference/joindone";
    }
	
    
}
